package cn.lili.controller.feign.union;

import cn.lili.modules.distribution.entity.dos.Distribution;
import cn.lili.modules.distribution.entity.vos.DistributionVO;
import cn.lili.modules.member.client.UnionMemberClient;
import cn.lili.modules.member.entity.dos.UnionMember;
import cn.lili.modules.member.entity.vo.NumberOfOwners;
import cn.lili.modules.union.service.UnionMemberService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class UnionMemberFeignController implements UnionMemberClient {

    private final UnionMemberService unionMemberService;

    @Override
    public List<Distribution> getUnionMemberPage(Integer pageNumber, Integer pageSize, String id, String memberName, String unionName) {
        DistributionVO distributionVO = new DistributionVO();
        distributionVO.setPageNumber(pageNumber);
        distributionVO.setPageSize(pageSize);
        distributionVO.setId(id);
        distributionVO.setMemberName(memberName);
        distributionVO.setUnionName(unionName);
        return unionMemberService.getUnionMemberPage(distributionVO);
    }

//    @Override
//    public List<UnionMember> getUnionMemberList() {
//        return unionMemberService.getUnionMemberList();
//    }

    /**
     * 根据类型，获取运营商下面的已加入工会的店主
     *
     * @param type 类型 1今日，2昨日......
     * @return 新增店主数量 + 总数
     */
    @Override
    public NumberOfOwners numberOfOwners(Integer type) {
        return unionMemberService.numberOfOwners(type);
    }

    /**
     * 根据类型，获取运营商下面的已加入工会的店主 ==>  业绩
     *
     * @param type 类型 1今日，2昨日......
     * @return 新增业绩数 + 总数
     */
    @Override
    public NumberOfOwners shopOwnersTurnover(Integer type) {
        return unionMemberService.shopOwnersTurnover(type);
    }

    @Override
    public List<UnionMember> getUnionMemberByIdList(List<String> idList) {
        LambdaQueryWrapper<UnionMember> unionMemberLambdaQueryWrapper = new LambdaQueryWrapper<>();
        unionMemberLambdaQueryWrapper.in(UnionMember::getMemberId, idList);
        return unionMemberService.list(unionMemberLambdaQueryWrapper);
    }

    @Override
    public List<UnionMember> getUnionMemberByUnionIdList(List<String> unionIdList) {
        LambdaQueryWrapper<UnionMember> memberLambdaQueryWrapper = new LambdaQueryWrapper<>();
        memberLambdaQueryWrapper.in(UnionMember::getUnionId, unionIdList);
        memberLambdaQueryWrapper.orderByDesc(UnionMember::getCreateTime);
        memberLambdaQueryWrapper.select(UnionMember::getId, UnionMember::getJoinTime, UnionMember::getUnionId, UnionMember::getCreateTime, UnionMember::getMemberId);
        return unionMemberService.list(memberLambdaQueryWrapper);
    }
}
